<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>register</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">td img {display: block;}</style>
<script src="GUI/add_on/image_rollover.js" type="text/javascript"></script>
<!--Fireworks CS3 Dreamweaver CS3 target.  Created Fri Nov 20 01:13:24 GMT-0800 (Pacific Standard Time) 2009-->
<link href="GUI/add_on/login.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/GooWhere/json.js"></script>
<script type="text/javascript">

           var name;
           var email;
           var pw;
           var pw_confirm;

           //register users function
           function register(){
                closeRegMessage();
                //get inputs from text boxes.
                name = document.getElementById('reg_username').value;
                email = document.getElementById('reg_email').value;
                pw = document.getElementById('reg_password').value;
                pw_confirm = document.getElementById('reg_password_confirm').value;

                //test password
                if(pw==pw_confirm){
                    setRegister(name,email,pw);
                }
                else{
                    showRegMessage();
                    document.getElementById("message_reg").innerHTML = "Passwords don't match!";
                }
            }

            function setRegister(userName, email, passWord){
                var url = "PlayerRegisterServlet?userName=" + userName + "&email=" + email + "&passWord=" +passWord;
                if (typeof XMLHttpRequest != "undefined") {
                    req = new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                }
                req.open("GET", url, true);
                req.onreadystatechange = regrequestcallback;
                req.send(null);
            }

            function regrequestcallback() {
                if (req.readyState == 4) {
                    var response = req.responseText.parseJSON();

                    //username is already used in the database and could not be added
                    if (response.length>0) {
                        showRegMessage();
                        document.getElementById("message_reg").innerHTML = name+" is already a user in our database!";
                    }
                    else{
                        alert(name + " has been added!");
                        closeRegisterWindow();
                        closeRegMessage();
                    }

                }
            }

            function showRegMessage()
            {
                 document.getElementById("message_bg").style.display = 'block';
                 document.getElementById("message_reg").style.display = 'block';
            }
            function closeRegMessage()
            {
                 document.getElementById("message_reg").innerHTML = "";
                 document.getElementById("message_bg").style.display = 'none';
                 document.getElementById("message_reg").style.display = 'none';
            }

            //make sure names do not have spaces.
            function hasSpaces(text){
                //pops up message and delete the space if space is detected.
                if(text.value.match(/\s/g)){
                    document.getElementById("message_window").style.display = 'block';
                    document.getElementById("message").innerHTML = "Sorry no space is allowed for user names.";
                    text.value=text.value.replace(/\s/g,'');
                }
            }


</script>

</head>
<body bgcolor="#ffffff" onload="MM_preloadImages('GUI/images/register/register_over_r2_c2.png','GUI/images/register/btn_register_over.png','GUI/images/register/btn_cancel_over.png')">

<div id="txt_reg_username">
<form id="form_reg_username" name="form_reg_username" method="post" action="">
    <input type="text" name="reg_username" id="reg_username" onkeyup="hasSpaces(this);" value="Player Name"/>
</form>
</div>
<div id="txt_reg_email">
<form id="form_reg_email" name="form_reg_email" method="post" action="">
    <input type="text" name="reg_email" id="reg_email" value="E-mail Address"/>
</form>
</div>
<div id="txt_reg_password">
<form id="form_reg_password" name="form_reg_password" method="post" action="">
    <input type="text" name="reg_password" id="reg_password" value="Password"/>
</form>
</div>
<div id="txt_reg_password_confirm">
<form id="form_reg_password_confirm" name="form_reg_password_confirm" method="post" action="">
    <input type="text" name="reg_password_confirm" id="reg_password_confirm" value="Password Again"/>
</form>
</div>

<div id="btn_register"><a href="#" onclick="register()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btn_register','','GUI/images/register/btn_register_over.png',1)"><img src="GUI/images/register/btn_register.png" name="btn_register" width="83" height="27" border="0" id="btn_register2" /></a></div>
<div id="btn_cancel"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('btn_cancel','','GUI/images/register/btn_cancel_over.png',1);this.style.cursor='pointer';" onclick="closeRegisterWindow()"><img src="GUI/images/register/btn_cancel.png" name="btn_cancel" width="76" height="27" border="0" id="btn_cancel2" /></a></div>
<table border="0" cellpadding="0" cellspacing="0" width="542">

<!-- fwtable fwsrc="Untitled" fwpage="Page 1" fwbase="register.png" fwstyle="Dreamweaver" fwdocid = "234125648" fwnested="0" -->
  <tr>
   <td><img src="GUI/images/register/spacer.gif" width="445" height="1" border="0" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="75" height="1" border="0" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="22" height="1" border="0" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>

  <tr>
   <td colspan="3"><img name="register_r1_c1" src="GUI/images/register/register_r1_c1.png" width="542" height="17" border="0" id="register_r1_c1" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="1" height="17" border="0" alt="" /></td>
  </tr>
  <tr>
   <td><img name="register_r2_c1" src="GUI/images/register/register_r2_c1.png" width="445" height="34" border="0" id="register_r2_c1" alt="" /></td>
   <td><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('close','','GUI/images/register/register_over_r2_c2.png',1);this.style.cursor='pointer';" onclick="closeRegisterWindow()"><img src="GUI/images/register/register_r2_c2.png" name="close" width="75" height="34" border="0" id="close" /></a></td>
   <td><img name="register_r2_c3" src="GUI/images/register/register_r2_c3.png" width="22" height="34" border="0" id="register_r2_c3" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="1" height="34" border="0" alt="" /></td>
  </tr>
  <tr>
   <td colspan="3"><img name="register_r3_c1" src="GUI/images/register/register_r3_c1.png" width="542" height="387" border="0" id="register_r3_c1" alt="" /></td>
   <td><img src="GUI/images/register/spacer.gif" width="1" height="387" border="0" alt="" /></td>
  </tr>
</table>
<div id="message_bg" style="display:none"><img src="GUI/images/register/message_bg.png" width="447" height="22" border="0" alt="" /></div>
<div id="message_reg" style="display:none" class="message_data">Error Message goes here!</div>
</body>
</html>
